package com.fsc.app_news;

import java.util.ArrayList;

import com.fsc.app_bean.Recommend;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class RPageActivity extends Activity implements OnClickListener{
	private ImageView iv_back;
	private TextView tv_content;
	private ListView lv_Image;
	private ArrayList<Recommend> data;
	private Recommend list;
	private ImageAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_rpage);
		init();
		envet();
		data = new ArrayList<Recommend>();
		data.add(new Recommend("",R.drawable.tu2,R.drawable.tu1,R.drawable.tu3));
		
		adapter = new ImageAdapter(this);
		lv_Image.setAdapter(adapter);
		
		Intent intent = getIntent();
        if(intent!=null)
        {
        	String content = intent.getStringExtra("content");
            tv_content.setText(content);
       }
	}
	public void init(){
		iv_back = (ImageView) findViewById(R.id.iv_back);
		tv_content = (TextView) findViewById(R.id.tv_content);
		lv_Image = (ListView) findViewById(R.id.lv_Image);
	}
	public void envet(){
		iv_back.setOnClickListener(this);
	}
	class ImageAdapter extends BaseAdapter{
		private Context context;
  		//构造函数
  		public ImageAdapter(Context context) {  
  	        this.context = context;
  	    }
		@Override
		public int getCount() {
			return data.size();
		}

		@Override
		public Object getItem(int position) {
			return data.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder hodler = null; 
  	        if(convertView == null)  
  	        {  
  	        	hodler = new ViewHolder();
  	            convertView = LayoutInflater.from(context).inflate(R.layout.item_image, null); 
  	            hodler.image1 = (ImageView) convertView.findViewById(R.id.iv_image1); 
  	            hodler.image2 = (ImageView) convertView.findViewById(R.id.iv_image2); 
  	            hodler.image3 = (ImageView) convertView.findViewById(R.id.iv_image3); 
  	            convertView.setTag(hodler);         //表示给View添加一个格外的数据，  
  	        } else {  
  	        	hodler = (ViewHolder) convertView.getTag();//通过getTag的方法将数据取出来  
  	        } 
  	        list = data.get(position); 
	        hodler.image1.setImageResource(list.getImage1());
	        hodler.image2.setImageResource(list.getImage2()); 
	        hodler.image3.setImageResource(list.getImage3());
  	        return convertView;
		}
		
	}
	public class ViewHolder {
		private ImageView image1;
		private ImageView image2;
		private ImageView image3;
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.iv_back:
			finish();
			break;
		default:
			break;
		}
	}
}
